package where2go.sctu.com.zhiyou.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import java.util.ArrayList;
import java.util.List;

import where2go.sctu.com.zhiyou.R;
import where2go.sctu.com.zhiyou.fragment.LineAppraiseFragment;
import where2go.sctu.com.zhiyou.fragment.LineIntroFragment;
import where2go.sctu.com.zhiyou.fragment.LinePlanFragment;
import where2go.sctu.com.zhiyou.fragment.OderingAllFragment;
import where2go.sctu.com.zhiyou.fragment.OderingCompleteFragment;
import where2go.sctu.com.zhiyou.fragment.OderingPaymentFragment;

/**
 * Created by lenovo on 2018/5/9.
 */

public class OderingActivity extends AppCompatActivity {
    private OderingAllFragment oderingAllFragment;
    private OderingPaymentFragment oderingPaymentFragment;
    private OderingCompleteFragment oderingCompleteFragment;
    private RadioGroup radioGroup1;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_odering_layout);
        initview();
        changeFragment(new  OderingAllFragment().getOderingAllFragment() );
    }

    private void setIndexSelectedTwo(int index) {
        switch (index) {
            case 0:
                changeFragment(new  OderingAllFragment().getOderingAllFragment());
                break;
            case 1:
                changeFragment(new  OderingPaymentFragment().getOderingPaymentFragment());
                break;
            case 2:
                changeFragment(new OderingCompleteFragment().getOderingCompleteFragment());
                break;
            default:
                break;
        }
    }
    private void changeFragment(Fragment fm) {
        FragmentManager supportFragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = supportFragmentManager.beginTransaction();
        transaction.replace(R.id.detail_fragment1, fm);
        transaction.commit();
    }


    private void initview() {
        radioGroup1 = (RadioGroup)findViewById(R.id.radioGroup1);
        radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int arg1) {
                //遍历RadioGroup 里面所有的子控件。
                for (int index = 0; index < group.getChildCount(); index++) {
                    //获取到指定位置的RadioButton
                    RadioButton rb = (RadioButton)group.getChildAt(index);
                    //如果被选中
                    if (rb.isChecked()) {
                        setIndexSelectedTwo(index);  //方法二
                        break;
                    }
                }
            }
        });
    }
}
